//
//  mbSCEGJLCFHomeHeaderViewsYEtrK.m
//  qcb_ios
//
//  Created by Ji on 2018/8/24.
//  Copyright © 2018年 ski. All rights reserved.
//

#import "mbSCEGJLCFHomeHeaderViewsYEtrK.h"
#import "JLCFSliderView.h"
#import "kyXDatJLCFHomeBannerListModelrnSlVp.h"
#import "JLCFBaseWebViewController.h"

@interface mbSCEGJLCFHomeHeaderViewsYEtrK ()<JLCFSliderViewDataSource, JLCFSliderViewDelegate>

@property (nonatomic, strong) JLCFSliderView *AqgkBOsliderViewpiwthC;

@property (nonatomic, strong) NSArray *views;

@end

@implementation mbSCEGJLCFHomeHeaderViewsYEtrK

- (void)reloadWithBanners:(NSArray *)banners
{
    self.views = banners;
    
    if (self.AqgkBOsliderViewpiwthC) {
        [self.AqgkBOsliderViewpiwthC reloadData];
    }
    
}

- (instancetype)initWithFrame:(CGRect)frame
{
    
    if (self = [super initWithFrame:frame]) {
        
        
        if (!self.AqgkBOsliderViewpiwthC) {
            
            self.AqgkBOsliderViewpiwthC = [[JLCFSliderView alloc] initWithFrame:frame style:JLCFSliderViewPageControlStyleDot alignment:JLCFSliderViewPageControlAlignmentCenter];
            self.AqgkBOsliderViewpiwthC.wrapEnabled = YES;
            self.AqgkBOsliderViewpiwthC.autoScroll = YES;
            self.AqgkBOsliderViewpiwthC.disableScrollOnlyOneImage = YES;
            self.AqgkBOsliderViewpiwthC.unChoosedPageColor = RGBA(255, 255, 255, 0.4);
            self.AqgkBOsliderViewpiwthC.currentPageColor = QTZ_White;
            [self.AqgkBOsliderViewpiwthC setPageViewBottom:10];
            self.AqgkBOsliderViewpiwthC.delegate = self;
            self.AqgkBOsliderViewpiwthC.dataSource = self;
            [self addSubview:self.AqgkBOsliderViewpiwthC];
        }
        
    }
    
    return self;
    
}

- (NSInteger)numberOfItemsInSliderView:(JLCFSliderView *)AqgkBOsliderViewpiwthC
{
    return self.views.count;
}

- (UIView *)sliderView:(JLCFSliderView *)sliderView viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
    if (!view) {
        view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, sliderView.width, sliderView.height)];
        view.userInteractionEnabled = YES;
    }
    
    UIImageView *coverImageView = (UIImageView *)view;
    coverImageView.frame = CGRectMake(0, 0, sliderView.width, sliderView.height);
    coverImageView.userInteractionEnabled = YES;
    
    kyXDatJLCFHomeBannerListModelrnSlVp *image = (kyXDatJLCFHomeBannerListModelrnSlVp *)[self.views safeObjectAtIndex:index];
    
//    weakify(coverImageView);
//    [coverImageView setOnlineImage:image.imgurl complete:^(UIImage *image) {
//        strongify(coverImageView);
//        coverImageView.image = image;
//    }];
    [coverImageView setOnlineImage:image.imgurl];
    return coverImageView;
}

- (void)sliderView:(JLCFSliderView *)sliderView didSelectViewAtIndex:(NSInteger)index
{
    kyXDatJLCFHomeBannerListModelrnSlVp *image = (kyXDatJLCFHomeBannerListModelrnSlVp *)[self.views safeObjectAtIndex:index];
    
    JLCFBaseWebViewController *webVC = [[JLCFBaseWebViewController alloc] init];
    webVC.url = image.url;
    DBG(@"url : %@", image.url);
    [[[JinLiCaiFuApplicationEntrace shareEntrance] currentNavController] pushViewController:webVC animated:YES];
    
}

@end
